package servlet;

import pojo.Supplier;
import pojo.SupplierContact;
import service.SContactService;
import service.impl.SContactServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @auth 吴阳基
 * @date 2024/1/2 14:48
 */
@WebServlet("/list")
public class ListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html; charset=UTF-8");

        SContactService contact = new SContactServiceImpl();
        List<SupplierContact> supplierContacts = contact.byPidCnameList(null, 0);
        List<Supplier> suppliers = contact.SupplierList();

        req.setAttribute("supplierContacts", supplierContacts);
        req.setAttribute("suppliers", suppliers);

        req.getRequestDispatcher("index.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
